<?php
	require_once("conexion/conexion.php");
	function BuscaClientes($area)
	{
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql="select CliRSocial,ArCliEstado from areacliente ac inner join clientes on ac.clirut=clientes.clirut where aecod='".$area."' and ArCliActivo=0 order by CliRSocial asc";
		$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
		$fila = mysql_num_rows($res);
		$con->cerrarBD();
		$cadena = "";
		$aux=0;
		while($reg = mysql_fetch_array($res))
		{
			if($aux==0)
			{
				$aux=1;
				$cadena = $reg['CliRSocial']." (".$reg['ArCliEstado'].")";
			}
			else
			{
				$cadena = $cadena."<br>".$reg['CliRSocial']." (".$reg['ArCliEstado'].")";
			}
		}
		
		return $cadena;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />

<script src="include_js/jquery.js" type="text/javascript"></script>
<script>
function EditarStock(valor)
{
	codigo = document.getElementById("tbBodega").rows[valor].cells[0].innerText;
	$.ajax({
				type: 'POST',
				url: 'Editar/Carga_Editar_AECliente.php',
				data: {codigo:codigo},
				success: function(data) {
					$('#tabla2').html(data);
				}
			})
}

function Buscar()
{
	document.getElementById('txtBuscar').style.display='block';
	document.getElementById('txtBuscar').focus();
}

function buscar2(txt) 
{ 
  txt = txt.toUpperCase();
  obj=document.getElementById('tbBodega'); 
  // Recorremos todas las filas de la tabla 
  for (i=2;ele=obj.getElementsByTagName('tr')[i];i++) 
  { 
  	//alert('pasa');
    // elegimos la primera celda de la fila 
    celda = ele.getElementsByTagName('td')[1];
	fila = obj.getElementsByTagName('tr')[i];
    // averiguamos que hay dentro de la celda 
    dato = celda.innerHTML; 
	//alert(dato);
    // vemos si coincide con lo que se ha escrito en el cuadro de texto 
    iz = dato.substr(0,txt.length); 
    fila.style.display = (txt==iz) ? '' : 'none'; 
  } 
} 
</script>
</head>

<body>
<form name="analisis" id="analisis" method="post">
<?php
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql="select distinct
					AENombre,
					ac.AECod
					
					from areacliente ac
					inner join areaextraccion ae on
					ae.AECod=ac.AECod where 1 order by ae.aecod";
		$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
		$con->cerrarBD();
?>
<div style="height:5px"></div>
<div class='option2'><div style="float:left"><label style="font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;">Areas con sus respectivos Clientes Ingresados.</label></div><div style="float:right;"><img src="imagen/cerrar.png" width="16" height="16" onclick="CerrarDatos();" style="cursor: pointer; border: 1px solid #990000;" alt="Cerrar" /></div><div style="float:left"><input name="txtBuscar" id="txtBuscar" type="text" style="display:none;" onkeyup="buscar2(this.value)"/></div><div style="clear:both"></div></div>

  <div class="cabecera">
   <table class="fija" border="0" cellpadding="0" cellspacing="0" id="tbBodega">
      <thead class="fija">
      	<tr class="fija">
		  <th width="10%" class="fija">cod</th>
      	  <th width="32%" class="fija">area&nbsp;<img src="imagen/IconoBuscar.png" width="12" height="12" alt="Buscar" onclick="Buscar();" style="cursor: pointer;"/></th>
      	  <th width="56%" class="fija">cliente</th>
		  <th width="2%" class="fija">&nbsp;</th>
      	</tr>
      </thead>
      <tbody class="fija">
         <tr class="fija"><td colspan="4" class="fija" style="margin-left:20px; ">&nbsp;</td></tr>
		 <?php
		$aux = 2;
		while($reg = mysql_fetch_array($res))
		{
			$clientes = BuscaClientes($reg['AECod']);
			if(($aux % 2)==0)
			{
				echo "<tr class='filaImpar' id='".$aux."'>";
				echo "<td width=\"10%\" style='text-align:lefth;padding-left:20px;'>".$reg['AECod']."</td>";
				echo "<td width=\"32%\" style='text-align:lefth;padding-left:20px;'>".$reg['AENombre']."</td>";
				echo "<td width=\"56%\" style='text-align:lefth;padding-left:30px;'>".$clientes."</td>";
				echo "<td style='text-align:center'><img src='imagen/edit_icon.gif' width='16' height='16' alt='Editar' style='cursor: pointer;' onclick='EditarStock($aux);'/></td>";
				echo "</tr>";
			}
			else
			{
				echo "<tr class='filaPar' id='".$aux."'>";
				echo "<td width=\"10%\" style='text-align:lefth;padding-left:20px;'>".$reg['AECod']."</td>";
				echo "<td width=\"32%\" style='text-align:lefth;padding-left:20px;'>".$reg['AENombre']."</td>";
				echo "<td width=\"56%\" style='text-align:lefth;padding-left:30px;'>".$clientes."</td>";
				echo "<td style='text-align:center'><img src='imagen/edit_icon.gif' width='16' height='16' alt='Editar' style='cursor: pointer;' onclick='EditarStock($aux);'/></td>";
				echo "</tr>";
			}
			$aux++;
		}
		?>
      </tbody>
   </table>       
</div>
<div id="eliminar"></div>
</form>
</body>
</html>
